package demo.sk.calcite;

import org.apache.calcite.sql.*;
import org.apache.calcite.sql.parser.SqlParseException;
import org.apache.calcite.sql.parser.SqlParser;
import org.apache.calcite.sql.parser.SqlParserPos;

/**
 * @author 支绍昆
 * 2022/12/27
 **/
/*
    1.执行javacc解析Parser.jj生成源码于/target/generated-sources
 */
public class Main {

    private final static String sql1 = "select a from table_one where a='1'";
    private final static String sql2 = "select a,b,c,d from table_one ma left join table_tow sl on ma.j = sl.j where ma.a = '1' ";

    public static void main(String[] args) {
        SqlDialect mysqlDialect = SqlDialect.DatabaseProduct.MYSQL.getDialect();
        SqlParser parser = demo.sk.calcite.SqlParserUtils.createParser(mysqlDialect);
        try {
            SqlNode sqlNode = parser.parseQuery(sql1);
            SqlKind kind = sqlNode.getKind();
            SqlParserPos parserPosition = sqlNode.getParserPosition();
            String s1 = sqlNode.toString();
            System.out.println(sqlNode.toString());

            SqlSelect select = (SqlSelect) sqlNode;
            System.out.println(select.getFrom());

        } catch (SqlParseException e) {
            throw new RuntimeException(e);
        }
    }
}
